package sqlist;

import java.util.ArrayList;
import java.util.Random;

class Card{
    private String suit;
    private int n;

    public Card(String suit, int n) {
        this.suit = suit;
        this.n = n;
    }

    public String getSuit() {
        return suit;
    }

    public void setSuit(String suit) {
        this.suit = suit;
    }

    public int getN() {
        return n;
    }

    public void setN(int n) {
        this.n = n;
    }

    @Override
    public String toString() {
        return "[" + suit+" "+n+"]";
    }
}


public class TestCard {
    public static final String[] suits = {"♠️","♥️","♦️","♣️"};
    public static ArrayList<Card> buyCards(){
        ArrayList<Card> cards = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j < 14; j++) {
                Card card = new Card(suits[i],j);
                cards.add(card);
            }

        }
        return cards;
    }

    public static void shuffle(ArrayList<Card> cards){
        for (int i = 51; i > 0 ; i--) {
            Random random  =new Random();
            int index = random.nextInt(i);
            swap(cards,index,i);
        }

    }
    private static void swap(ArrayList<Card> cards,int i,int j){
        Card tmp = cards.get(i);
        cards.set(i,cards.get(j));
        cards.set(j,tmp);
    }


    public static void main(String[] args) {
        ArrayList<Card> cards = buyCards();
        shuffle(cards);
        System.out.println(cards);

        ArrayList<Card> hand1 = new ArrayList<>();
        ArrayList<Card> hand2 = new ArrayList<>();
        ArrayList<Card> hand3 = new ArrayList<>();

        ArrayList<ArrayList<Card>> hands = new ArrayList<>();
        hands.add(hand1);
        hands.add(hand2);
        hands.add(hand3);

        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card = cards.remove(0);
                hands.get(j).add(card);
            }
        }
        System.out.println(hand1);
        System.out.println(hand2);
        System.out.println(hand3);
    }
}
